SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE  PROCEDURE dbo.DnnProduct_AddSearchItemWordPosition
	@SearchItemWordID int,
	@ContentPositions varChar(2000)
AS

	SET NOCOUNT ON

	DECLARE @TempList table
	(
		ItemWordID int,
		Position int
	)

	DECLARE @Position varchar(10), @Pos int

	SET @ContentPositions = LTRIM(RTRIM(@ContentPositions))+ ','
	SET @Pos = CHARINDEX(',', @ContentPositions, 1)

	IF REPLACE(@ContentPositions, ',', '') <> ''
	BEGIN
		WHILE @Pos > 0
		BEGIN
			SET @Position = LTRIM(RTRIM(LEFT(@ContentPositions, @Pos - 1)))
			IF @Position <> ''
			BEGIN
				INSERT INTO @TempList (ItemWordID, Position) VALUES (@SearchItemWordID, CAST(@Position AS int)) 
			END
			SET @ContentPositions = RIGHT(@ContentPositions, LEN(@ContentPositions) - @Pos)
			SET @Pos = CHARINDEX(',', @ContentPositions, 1)

		END
	END	

	INSERT INTO dbo.DnnProduct_SearchItemWordPosition (
		[SearchItemWordID],
		[ContentPosition]) 
	SELECT ItemWordID, Position FROM @TempList










GO
